<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    :root {
      --primary-color: #22254b;
      --second-color: #373b69;
    }

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    html {
      font-size: 1.66vw;
    }

    body {
      background-color: var(--primary-color);
    }

    header {
      position: relative;
      height: 4rem;
      background-color: var(--second-color);
    }

    .search {
      position: absolute;
      right: 2rem;
      top: 50%;
      transform: translateY(-50%);
      width: 9rem;
      height: 2rem;
      border-radius: 1rem;
      padding: 10px;
      background-color: transparent;
      color: #fff;
      border: 2px solid var(--primary-color);
    }

    .search:focus {
      outline: none;
      background-color: var(--primary-color);
    }

    main {
      display: grid;
      gap: 10px;
      max-width: 80vw;
      margin-inline: auto;
      padding-block: 0.8rem;
      grid-template-columns: repeat(auto-fit, minmax(max(150px, 15vw), 1fr));
      box-shadow: 0px 0 5px rgba(0, 0, 0, 0.3);
    }

    .movie {
      background-color: var(--second-color);
      box-shadow: 0 4px 5px rgba(0, 0, 0, 0.2);
      position: relative;
      overflow: hidden;
      border-radius: 3px;
      height: 100%;
    }

    .img-container {
      padding-top: 160%;
      position: relative;
    }

    .img-container img {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .movie-info {
      display: flex;
      justify-content: space-around;
      align-items: center;
      padding: 1rem 0.5rem;
    }

    .movie-info h3 {
      color: #fff;
      font-size: .5rem;
    }

    .movie-info span {
      background-color: rgba(0, 0, 0, 0.3);
      border-radius: 5px;
      padding: 0.2rem 0.6rem;
      font-size: 0.8rem;
      font-weight: 600;
    }

    .movie-info .green {
      color: green;
    }

    .movie-info .orange {
      color: orange;
    }

    .movie-info .red {
      color: red;
    }

    .overview {
      position: absolute;
      left: 0;
      bottom: 0;
      max-height: 100%;
      overflow-y: auto;
      padding: 0.5rem;
      background-color: rgba(255, 255, 255, 1);
      transform: translateY(102%);
      font-size: 0.7rem;
      transition: all 0.2s ease-in;
    }

    .movie:hover .overview {
      transform: translateY(0%);
    }
  </style>
</head>

<body>
  <header>
    <form id="form">
      <input type="text" id="search" class="search" placeholder="搜索" />
    </form>
  </header>
  <div class="movie-wrap">
    <main>

    </main>
  </div>
</body>
<script>
  const top250 = "https://api.wmdb.tv/api/v1/top?type=Imdb&skip=0&limit=250&lang=Cn";
  function getMovies(url) {
    fetch(url).then(res => {
      res.json().then(result => {
        console.log(result);
        result.forEach(item => {
          const movieEl = document.createElement('div');
          movieEl.innerHTML = `
        <div class="movie">
          <div class="img-container">
            <img
              src="${item.data[0].poster}"
              alt=""
            />
          </div>
          <div class="movie-info">
            <h3>${item.data[0].name}</h3>
            <span class="${item.doubanRating >= 6.0 ? item.doubanRating >= 9.0 ? 'green' : 'orange' : 'red'}">${item.doubanRating}</span>
          </div>
          <div class="overview">
            <h3>概览</h3>
            <div class="text">
              ${item.data[0].description}
            </div>
          </div>
        </div>
        `
          let mainWrap = document.querySelector('main');
          mainWrap.appendChild(movieEl)
        })
      })
    })
  }

  getMovies(top250);
</script>

</html>